package jane.mvc.engine;

import jane.mvc.annotations.MVCParam;
import jane.mvc.exceptions.NotImplementedException;

import java.lang.annotation.Annotation;
import java.util.ArrayList;

public class JaneMVCMethod
{

	private java.lang.reflect.Method _method;
	private Class<?> returnType;

	private Class<?>[] paramTypes;

	private String controllerName;
	private String webname;
	private Annotation[] annotations;
	private boolean hasParameters;
	private Annotation[][] paramAnnotations;
	private ArrayList<String> paramsNamesList;

	public ArrayList<String> getParamsNamesList()
	{

		paramsNamesList = new ArrayList<String>();
		for (Annotation[] annarr : this.getParamAnnotations())
		{
			for (Annotation annotation : annarr)
			{
				if (annotation instanceof MVCParam)
				{
					MVCParam a = (MVCParam) annotation;
					paramsNamesList.add(a.name());
				}
			}

		}

		return paramsNamesList;
	}

	public Class<?>[] getParameterTypes()
	{
		return this.paramTypes;
	}

	public boolean hasParameters()
	{
		return hasParameters;
	}

	public void setParameterTypes(Class<?>[] paramTypes)
	{
		if (paramTypes.length > 0)
		{
			this.hasParameters = true;
		} else
		{
			this.hasParameters = false;
		}

		this.paramTypes = paramTypes;
	}

	public Class<?> getReturnType()
	{
		return this.returnType;
	}

	public void setReturnType(Class<?> class1)
	{
		this.returnType = class1;
	}

	public java.lang.reflect.Method getMethod()
	{
		return this._method;
	}

	public void setMethod(java.lang.reflect.Method method)
	{
		this._method = method;
	}

	public String getMethodName()
	{
		return this.getMethod().getName();
	}

	public void setMethodName(String methodName) throws NotImplementedException
	{
		throw new NotImplementedException();
	}

	public String getControllerName()
	{
		return this.controllerName;
	}

	public void setControllerName(String controllerName)
	{
		this.controllerName = controllerName;
	}

	public String getWebname()
	{
		return this.webname;
	}

	public void setWebname(String webname)
	{
		this.webname = webname;

	}

	public Annotation[] getAnnotations()
	{
		return this.annotations;
	}

	public void setAnnotations(Annotation[] annotations)
	{

		this.annotations = annotations;

	}

	public Annotation[][] getParamAnnotations()
	{
		return paramAnnotations;
	}

	public void setParameterAnnotations(Annotation[][] parameterAnnotations)
	{

		this.paramAnnotations = parameterAnnotations;
	}
}
